/**
 * COOKIE存储
 * @param {string} key 键
 * @param {string} val 数据
 * @param {number} s   时间/s
 */
function setcookie(key, val, s) {
    if (typeof val == 'object') {
        val = JSON.stringify(val);
    }
    const p = new Date;
    p.setTime(p.getTime() - 1000 * 60 * 60 * 8 + 1000 * s)
    document.cookie=`${key}=${val};expires=${p}`
}




/**
 * 取数据
 * @param {string} key 
 * @returns {obj}
 */

function getcookie(key) {
    let arr = document.cookie.split(';')
    // for (let i = 0; i < arr.length; i++) {
    //     let item = arr[i]
    //     let temp = item.split('=')
    //     if (temp[0] == key) {
    //         return temp[1]
    //     }
    // }
    let obj ={}
    arr.forEach((item,i)=>{
        let temp = item.split('=')
        let key = temp[0];
        let val = temp[1];
        obj[key]= val
    })
    if (key) {
        return obj[key]
    }
    return obj
}


/**
 * COOKIE删除
 * @param {string} key 键
 */
function removecookie(key) {
    setcookie(key, null, -1)
}
